import bb.cascades 1.3
import bb.Favorites 1.0
import bb.Setting 1.0
import "lib"
import "controls"

Page {
    id: root
    titleBar: TitleBar {
        title: qsTr("Cache Manager")
    }

    onCreationCompleted: {
        _Setting.cacheSizeChanged.connect(cacheFinished)
        _Favorites.accessCountChanged.connect(accessCountChanged)
        
        _Setting.getCacheSize()
        _Favorites.getAccessCount()
    }
    
    function accessCountChanged(count){
        accessSize.text = qsTr("Number of database: %1").arg(count);
    }
    
    function cacheFinished(size){
        cachesize.text = qsTr("The size of the cache file: ") + size;
    }

    Container {
        MenuItem {
            Padding {
                preferredHeight: 100
                layout: DockLayout {
                }
                Container {
                    horizontalAlignment: HorizontalAlignment.Left
                    verticalAlignment: VerticalAlignment.Center
                    Label {
                        id: cachesize
                        textStyle.base: com.titleStyle
                    }
                }
            }

            Divider {
                topMargin: 0
                bottomMargin: 0
            }
        }

        MenuItem {
            Padding {
                preferredHeight: 100
                layout: DockLayout {
                }
                Container {
                    horizontalAlignment: HorizontalAlignment.Left
                    verticalAlignment: VerticalAlignment.Center
                    Label {
                        id: accessSize
                        textStyle.base: com.titleStyle
                    }
                }
            }

            Divider {
                topMargin: 0
                bottomMargin: 0
            }
        }
    }
    
    actions: [
        ActionItem {
            title: qsTr("Delete")
            ActionBar.placement: ActionBarPlacement.OnBar
            onTriggered: {
                _Setting.clearCache();
                _Favorites.emptyAccess();
            }
        }
    ]

    attachedObjects: [
        Common {
            id: com
        }
    ]
}
